package com.woniuxy.educationplatform.mapper;

import com.woniuxy.educationplatform.bean.*;
import net.sf.jsqlparser.expression.DateTimeLiteralExpression;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@Mapper
public interface QuesMapper {

   /**
    * 查询所有题干
    * @return
    */
   List<QuesBean> findAll(@Param("q") QuesBean quesBean);

   /**
    * 根据ID查询题目
    * @param id
    * @return
    */
   @Results({
           @Result(id=true,property = "id",column = "id",javaType = Long.class),
           @Result(property = "pointValue",column = "point_value",javaType = Integer.class),
           @Result(property = "quesContent",column = "question_content",javaType = String.class),
           @Result(property = "difficulty",column = "difficulty",javaType = Integer.class),

   })
   @Select("select * from question_info where id = #{id}")
   QuesBean getOneById(Long id);



   /**
    * 新增题干
    * @param quesBean
    * @return 受影响的行数
    */
   @Options(
           useGeneratedKeys = true,
           keyProperty = "q.id"
   )
   @Insert("insert into question_info " +
           "(point_value,question_content,image,difficulty,modify_time,done_nums,correct_rate,fk_test_id,fk_subject_id,fk_knowpoint_id,fk_video_id,fk_ques_type)" +
           " values(#{q.pointValue},#{q.quesContent},#{q.image},#{q.difficulty},now(),#{q.doneNums},#{q.correctRate},#{q.testBean.id},#{q.subjectBean.id},#{q.knowPointBean.id},#{q.videoBean.id},#{q.quesType.id})")
   int addQuesBean(@Param("q") QuesBean quesBean);


   /**
    * 修改题干
    * @param quesBean
    * @return
    */

   @Update("<script>" +
           "update question_info" +
           "<set>" +
           "<if test='q.pointValue != null'>" +
           " point_value = #{q.pointValue}," +
           "</if>" +
           "<if test='q.quesContent != null'>" +
           " question_content = #{q.quesContent}," +
           "</if>" +

           "<if test='q.difficulty != null'>" +
           " difficulty = #{q.difficulty}," +
           "</if>" +

           "<if test='q.doneNums != null'>" +
           " done_nums = #{q.doneNums}," +
           "</if>" +
           "<if test='q.correctRate != null'>" +
           " correct_rate = #{q.correctRate}," +
           "</if>" +
           "</set>" +
           "where id = #{q.id}" +
           "</script>")
   int updateQuesBean(@Param("q") QuesBean quesBean);

   /**
    * 删除题目
    * @param id
    * @return 受影响的行数
    */
   @Delete("delete from question_info where id = #{id}")
   int deleteQuesBean(@Param("id")Long id);


}
